$(function () {
    $("#jqGrid").jqGrid({
        url: '../pvmgfirmwarelog/list',
        datatype: "json",
        colModel: [			
			{ label: 'logId', name: 'logId', index: 'log_id', width: 50, key: true },
			{ label: '固件类型', name: 'firmwareType', index: 'firmware_type', width: 80 }, 			
			{ label: '固件版本', name: 'firmwareVersion', index: 'firmware_version', width: 80 }, 			
			{ label: '下载地址', name: 'downloadPath', index: 'download_path', width: 80 }, 			
			{ label: '用户IP地址', name: 'ipAddress', index: 'ip_address', width: 80 }, 			
			{ label: '项目编号 PVMG10、PVL01', name: 'productName', index: 'product_name', width: 80 }, 			
			{ label: 'MD5值', name: 'mdKey', index: 'md_key', width: 80 }, 			
			{ label: '用户ID', name: 'userId', index: 'user_id', width: 80 }, 			
			{ label: '设备类型', name: 'deviceType', index: 'device_type', width: 80 }, 			
			{ label: '默认0-不强制更新, 1为强制更新', name: 'mustUpdate', index: 'must_update', width: 80 }, 			
			{ label: '固件运行环境版本号', name: 'appVersion', index: 'app_version', width: 80 }, 			
			{ label: '文件名称', name: 'fileName', index: 'file_name', width: 80 }, 			
			{ label: '升级花费时间', name: 'upgradeTime', index: 'upgrade_time', width: 80 }, 			
			{ label: '开始时间', name: 'beginTime', index: 'begin_time', width: 80 }, 			
			{ label: '结束时间', name: 'endTime', index: 'end_time', width: 80 }, 			
			{ label: '操作结果', name: 'operateResult', index: 'operate_result', width: 80 }, 			
			{ label: '操作日志', name: 'operateLog', index: 'operate_log', width: 80 }, 			
			{ label: '动作类型 (1-升级；2-下载；)  ', name: 'operateType', index: 'operate_type', width: 80 }, 			
			{ label: '备注', name: 'remark', index: 'remark', width: 80 }, 			
			{ label: '日志创建时间', name: 'createTime', index: 'create_time', width: 80 }, 			
			{ label: 'app的语言', name: 'appLanguage', index: 'app_language', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		pvMgFirmwareLog: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.pvMgFirmwareLog = {};
		},
		update: function (event) {
			var logId = getSelectedRow();
			if(logId == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(logId)
		},
		saveOrUpdate: function (event) {
			var url = vm.pvMgFirmwareLog.logId == null ? "../pvmgfirmwarelog/save" : "../pvmgfirmwarelog/update";
			$.ajax({
				type: "POST",
			    url: url,
			    data: JSON.stringify(vm.pvMgFirmwareLog),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var logIds = getSelectedRows();
			if(logIds == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../pvmgfirmwarelog/delete",
				    data: JSON.stringify(logIds),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(logId){
			$.get("../pvmgfirmwarelog/info/"+logId, function(r){
                vm.pvMgFirmwareLog = r.pvMgFirmwareLog;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});